package com.wind.sample.rocketmq.consumer;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        topic = "${demo.rocketmq.topic}",
        consumerGroup = "${demo.rocketmq.consumer-group}",
        consumeMode = ConsumeMode.CONCURRENTLY  // 并发消费模式
)
public class DemoConsumer implements RocketMQListener<String> {

    @Override
    public void onMessage(String message) {
        // 此处实现消费逻辑
        System.out.println("======= 收到消息 =======");
        System.out.println("内容: " + message);
        System.out.println("处理线程: " + Thread.currentThread().getName());

        // 模拟业务处理
        try {
            Thread.sleep(500); // 模拟处理耗时
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 若抛出异常会自动触发重试
    }
}